package com.habdqn.ssm.etm.controller;

import com.habdqn.ssm.etm.entity.Department;
import com.habdqn.ssm.etm.entity.EnterpriseTalent;
import com.habdqn.ssm.etm.service.DepartmentService;
import com.habdqn.ssm.etm.service.EnterpriseTalentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (EnterpriseTalent)表控制层
 *
 * @author xing.jiejian
 * @since 2019-11-16 10:51:39
 */
@Controller
@RequestMapping("/enterpriseTalent")
public class EnterpriseTalentController {
    /**
     * 服务对象
     */
    @Resource
    private EnterpriseTalentService enterpriseTalentService;
    @Resource
    private DepartmentService departmentService;

    @GetMapping("/list")
    public String list(@RequestParam(name = "pageNo",defaultValue = "1") int pageNo,
                       @RequestParam(name = "pageSize",required = false,defaultValue = "5") int pageSize,
                       @RequestParam(name = "departmentId",required = false,defaultValue = "-1") int departmentId,
                       Model model){
        // 查询部门集合
        List<Department> departments = departmentService.queryAll();
        // 获取总记录数
        int totalCount = enterpriseTalentService.queryCountByDepartmentId(departmentId);
        // 计算总页数
        int pageCount = (totalCount + pageSize - 1) / pageSize;
        // 查询分页数据
        List<EnterpriseTalent> ets = enterpriseTalentService.queryAllByLimit(pageNo,pageSize,departmentId);
        //放入作用域
        model.addAttribute("departments",departments);
        model.addAttribute("ets",ets);
        model.addAttribute("pageNo",pageNo);
        model.addAttribute("pageSize",pageSize);
        model.addAttribute("departmentId",departmentId);
        model.addAttribute("totalCount",totalCount);
        model.addAttribute("pageCount",pageCount);
        return "list";
    }
}